package ochart.serialization
{
	import com.adobe.serialization.json.JSON;
	
	import ochart.chartClasses.IChartObject;
	import ochart.serialization.json.oChart.JSONSerializeFactory;
	import ochart.serialization.json.ofc.OFCSerializeFactory;
	import ochart.serialization.xml.oChart.XMLSerializeFactory;

	public class SerializeFactory
	{
		private static var _instance:SerializeFactory = null;

		public static function get instance():SerializeFactory
		{
			if(!_instance)
			{
				_instance = new SerializeFactory();
			}
			return _instance;
		}
		
		private var _format:String = null;
		
		public function get format():String
		{
			return _format;
		}
		
		public function set format(value:String):void
		{
			_format = value;
			
			switch(_format)
			{
				case SerializationFormat.JSON:
					this.factory = new JSONSerializeFactory();
					break;
				case SerializationFormat.XML:
					this.factory = new XMLSerializeFactory();
					break;
				case SerializationFormat.OFC:
					this.factory = new OFCSerializeFactory();
					break;
				default:
					this.factory = null;
			}
		}
		
		public var factory:ISerializeFactory = null;
		
		public function SerializeFactory()
		{
		}
		
		public function create(alias:String):ISerialzer
		{
			if(this.factory)
			{
				return factory.create(alias);
			}
			return null;
		}
	}
}